package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.banner.domain.Banner;
import com.ruoyi.banner.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Anonymous
@RestController
@Api(tags = "轮播图管理")
public class BannerController {

    @Autowired
    private BannerService service;

    @ApiOperation(value = "获取所有轮播图列表")
    @RequestMapping("/GetBannertAll")
    public AjaxResult GetBannerAll() {
        List<Banner> result = service.getBannerList();
        return AjaxResult.success(result);

    }

    @ApiOperation("新增轮播图")
    @PostMapping("/AddBanner")
    public AjaxResult AddBanner(@RequestBody Banner banner) {
        int resullt = service.addBanner(banner);
        return AjaxResult.success(resullt);
    }

    @ApiOperation("根据id查询轮播图")
    @GetMapping("/GetBannerByTitle")
    //根据轮播图id查询
    public AjaxResult GetBannerByTitle(String title) {
        return AjaxResult.success(service.queryBannerByTitle(title));
    }

    @ApiOperation("修改轮播图信息")
    @PostMapping("/ModifyBanner")
    public AjaxResult ModifyBanner(@RequestBody Banner banner) {
        service.updateBanner(banner);
        return AjaxResult.success();
    }

    @ApiOperation("删除轮播图信息")
    @GetMapping("/DeleteBanner")
    public  AjaxResult DeleteBanner(int id) {
        service.deleteBanner(id);
        return AjaxResult.success();
    }

}